home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15095 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.1 KB  |  54 lines

  1. Path: panoramix.fi.upm.es!dia!sacha
  2. From: sacha@diafi.upm.es (Sacha)
  3. Newsgroups: comp.lang.c++
  4. Subject: another overloading question
  5. Date: 3 Apr 1996 16:33:17 GMT
  6. Organization: CS Dept., Technical University of Madrid
  7. Sender: sacha@dia (Sacha)
  8. Distribution: world
  9. Message-ID: <4ju98d$3al@panoramix.fi.upm.es>
  10. NNTP-Posting-Host: alba.dia.fi.upm.es
  11.  
  12.  
  13. Hi,
  14.  
  15. Can I overload = for simple types?
  16.  
  17.  
  18. I mean, if for example I have:
  19.  
  20.     class Colour
  21.     {
  22.     private:
  23.       float r_, g_, b_;
  24.  
  25.     public:
  26.       Colour(float r, float g, float b) 
  27.         {r_=r; g_=g; b_=b;}
  28.     };
  29.  
  30. is there some way I can overload = so that I can do things like:
  31.  
  32.     Colour colour(0.99238, 0.172364, 0.273);
  33.  
  34.     int intensity = colour;
  35.  
  36.  
  37. such that intensity is assigned a value computed from r,g,b (e.g. the average)?
  38.  
  39.  
  40. I think someone else may have asked this, phrasing it all with lvalues and
  41. rvalues, but I lost the thread.
  42.  
  43. I suspect that the compiler treats simple types at compile time and there may be
  44. no way to do this. I suppose I can substitute it with a normal member function...
  45.  
  46. Any help much appreciated...
  47.  
  48. Sacha.
  49.  
  50.  
  51.  
  52. -- 
  53. "It's not just pork, Gilbert, it's power."
  54.